<?php
/**
 * 全局函数库
 */

/*********************************************************************************************************************************************************
 *   ===============
 *     通用函数
 *   ===============
 *********************************************************************************************************************************************************/


/**
 * 创建数据模型对象
 * 
 * @param string $module_name model名称  结构 <Modules Name>::<model Name> / <model Name> 示例: param::struct , type 
 */
function M( $module_name="" ) {

	$option = explode('::', $module_name );
	
	if ( count($option) == 2 ) {
		$name = $option[1];
		$module = $option[0];
	} else {
		$name = $option[0];
	}

	$model_file = ROOT_PATH  . '/../model'; 

	if ( $module != "" )  $model_file = $model_file. "/". $module;

	$model_file = $model_file . "/$name.class.php";

	if (!file_exists($model_file) ) die( "$name ($module) 文件不存在 <strong>$model_file</strong>" );

	require_once( $model_file );

	$class_name = "$name";
	if ( !class_exists($class_name) ) die( "$class_name 类不存在  $model_file" );

	$args = func_get_args();
	unset($args['0']);
	return newInstance($class_name,$class_name,$args);
}

function newInstance() {
    $arguments = func_get_args();
	print_r($arguments);

    $className = array_shift($arguments);
    $class = new ReflectionClass($className);
    return $class->newInstanceArgs($arguments);
}



function goto_404() {
	//http_response_code(404);
	die('404');

	exit();
}

function goto_503() {
	die('503');
	//http_response_code(503);
	exit();
}

function wprint_r( $data ) {
	echo "<pre>";
	print_r( $data );
	echo "</pre>";
}

function wecho( $data ) {
	echo "<pre>";
	echo $data;
	echo "</pre>";
}